uniform vec3 uColor;
uniform float uPercent;
uniform float uIntensity;
varying vec2 vUv;
varying vec3 vPositionWS;

#ifdef USE_MASK
uniform sampler2D tMask;
#endif

#ifdef USE_MASK_TRANSPARENT
uniform sampler2D tMask;
#endif

#ifdef USE_AOMAP
uniform sampler2D aoMap;
#endif 

void main() {
    if(vUv.x > uPercent)
        discard;

    #ifdef USE_MASK
    float mask = texture(tMask, vUv).r;
    if(mask < 0.5)
        discard;
    #endif

    vec3 color = uColor * uIntensity;
    gl_FragColor = vec4(color, 1.);

    #ifdef USE_MASK_TRANSPARENT
    gl_FragColor.a = texture(tMask, vUv).r;
    #endif

#ifdef USE_AOMAP
    gl_FragColor.rgb *= texture2D(aoMap, vec2(vPositionWS.x, -vPositionWS.z) / 3.97104 * 0.5 + 0.5).r;
#endif

    #include <tonemapping_fragment>
    #include <colorspace_fragment>
}
